package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.ReservationSearchModel;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/5/23 0023.
 * 订房查询适配器
 */

public class ReservationSearchAdapter extends SwipeMenuAdapter<ReservationSearchAdapter.ViewHolder> {

    private List<ReservationSearchModel.PRsvbillRoomListDtosBean> mList;
    private Context t;
    private OnItemClickListener listener;

    public ReservationSearchAdapter(Context context, List<ReservationSearchModel.PRsvbillRoomListDtosBean> list,OnItemClickListener listener){
        this.mList=list;
        this.listener=listener;
        this.t=context;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(t).inflate(R.layout.reservation_search_item,null);
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ViewHolder(realContentView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final ReservationSearchModel.PRsvbillRoomListDtosBean model=mList.get(position);
        holder.orderNum.setText(t.getString(R.string.order_num)+t.getString(R.string.space)+model.getCRONum());
        holder.name.setText(t.getString(R.string.name)+t.getString(R.string.space)+model.getOrgAcct());
        holder.roomCount.setText(t.getString(R.string.room_count)+t.getString(R.string.space)+model.getRmNumbers());
        holder.personCount.setText(t.getString(R.string.person_count)+t.getString(R.string.space)+model.getPersons()+t.getString(R.string.ren));
        holder.state.setText(t.getString(R.string.state)+t.getString(R.string.space)+model.getStatus());
        holder.agreeGuest.setText(t.getString(R.string.agree_guest)+t.getString(R.string.space)+model.getTaname());
        holder.arriveDate.setText(t.getString(R.string.arrive_date)+t.getString(R.string.space)+model.getArrdate()+t.getString(R.string.zhi)+model.getDptDate());
        holder.details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.ItemClickListener(model,position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        ImageView ivZhong;//钟点房
        ImageView ivVip;//vip
        ImageView ivLing;//领
        ImageView ivChuang;//床租房
        ImageView ivYu;//预约房

        TextView orderNum;//订单号
        TextView name;//名称
        TextView roomCount;//房数
        TextView personCount;//人数
        TextView state;//状态
        TextView agreeGuest;//协议客户
        TextView arriveDate;//到离日期
        Button details;//查看详情

        public ViewHolder(View itemView) {
            super(itemView);
            ivZhong= (ImageView) itemView.findViewById(R.id.iv_zhong);
            ivVip= (ImageView) itemView.findViewById(R.id.iv_vip);
            ivLing= (ImageView) itemView.findViewById(R.id.iv_ling);
            ivChuang= (ImageView) itemView.findViewById(R.id.iv_chuang);
            ivYu= (ImageView) itemView.findViewById(R.id.iv_yu);
            orderNum= (TextView) itemView.findViewById(R.id.tv_order_num);
            name= (TextView) itemView.findViewById(R.id.tv_name);
            roomCount= (TextView) itemView.findViewById(R.id.tv_count);
            personCount= (TextView) itemView.findViewById(R.id.tv_person_count);
            state= (TextView) itemView.findViewById(R.id.tv_state);
            agreeGuest= (TextView) itemView.findViewById(R.id.tv_agree_guest);
            arriveDate= (TextView) itemView.findViewById(R.id.tv_arrive_date);
            details= (Button) itemView.findViewById(R.id.bt_details);
        }

    }

    public interface OnItemClickListener{
        void ItemClickListener(ReservationSearchModel.PRsvbillRoomListDtosBean model,int position);
    }
}
